SAA = ('A', 'C', 'E', 'D', 'G', 'F', 'I', 'H', 'K', 'M', 'L', 'N', 'Q', 'P', 'S', 'R', 'T', 'W', 'V', 'Y')
#print SAA
DIPEPTIDE = []

for dipeptide in iters.product(SAA, repeat=2):
    DIPEPTIDE.append(''.join(dipeptide))
#print  DIPEPTIDE

# psi statistics, according to seqs, proteion and gap
def statisPsi(seqs, protein, gap):
    psi = np.zeros(len(seqs))
    loops = len(protein) - gap - 1
    for start in range(loops):
        dipeptide = protein[start:(start + gap + 2):(gap + 1)]
        index = seqs.index(dipeptide)
        psi[index] += 1
    # print sum(psi)
    psi = np.array(psi)
    psi = psi / sum(psi)
    return psi

# get gap1 dipeptide features psi matrix",
gap1_psi = np.zeros((len(train_data), len(DIPEPTIDE)))
for idx in range(len(train_data)):
    gap1_psi[idx] = statisPsi(DIPEPTIDE, train_data[idx], 1)
#print gap1_psi

#print statisPsi(DIPEPTIDE, 'MDFNPSEVASQVTNYIQAIAAAGVGVLALAIGLSAAWKYAKRFLKG', 1)

# output csv file of training features and label
df = pd.DataFrame(gap1_psi)
label = pd.Series([1 for i in range(len(train_tdata))]+ [0 for i in range(len(train_fdata))])
print (label[(len(train_tdata)-1):(len(train_tdata)+1)])
df['label'] = label
df.to_csv('./features/train_1-gap.csv')